#include "../iBe.h"

Controller::Controller():lastUpdate(0)
{};

Controller::~Controller()
{};

void Controller::update(const UINT64 &_time)
{
  internalUpdate(_time);
  lastUpdate = _time;
};


LocationController::LocationController(Turple3f &_loc):loc(_loc)
{};

LocationController::~LocationController()
{};

void LocationController::setTrack(TrackPtr _track)
{
  track = _track;
}

void LocationController::internalUpdate(const UINT64 &_time)
{
  if (track)
    {
      track->update(_time);
      loc = track->getValue();
    }
}


ControllerGroup::ControllerGroup()
{}

ControllerGroup::~ControllerGroup()
{}

ControllerGroup::UpdateFunc::UpdateFunc(const UINT64 &_time):time(_time)
{} 

void ControllerGroup::UpdateFunc::operator()(ControllerPtr _controller)
{
  _controller->update(time);
}

void ControllerGroup::addController(ControllerPtr _controller)
{
  controllers.push_back(_controller);
}

void ControllerGroup::internalUpdate(const UINT64 &_time)
{
  UpdateFunc func(_time);

  std::for_each(controllers.begin(), controllers.end(), func);
}
